﻿    
    
    /* js方法全选GridView里的CheckBox  
     * 
     * 说明:点击GridView标头上是的CheckBox,实现全选CheckBox列
     *      
     * 使用方法:
     *      <input type="checkbox" onclick="selectAll(this,GridView1);" />
     *
     * 参数说明:第一个参数为被点击的CheckBox,第二个参数为要全选(全不选)CheckBox列的GridView的ID
     */ 
    function selectAll(chkbox,gv)
    {
        var state = chkbox.checked;
                  
         var TargetBaseControl = document.getElementById(gv);  
         var TargetChildControl = chkbox; 
         
         var Inputs = TargetBaseControl.getElementsByTagName("input"); 
         for(var i=0;i<Inputs.length;i++)
         {
            if(Inputs[i].type == 'checkbox')
            {
                Inputs[i].checked = state;               
                  GridViewAllCheckBoxClick(Inputs[i].parentElement.parentElement.id,state);
               
             }
         }
         
//         if(state)
//         {
//             for(var j=0;j<Inputs.length;j++)
//             {
//                Inputs[j].parentElement.parentElement.style.backgroundColor="#C8C4DB";
//             }
//         }
//         else
//         {
//             for(var k=0;k<Inputs.length;k++)
//             {
//                if(k%2 == 0)
//                {
//                    Inputs[k].parentElement.parentElement.style.backgroundColor="#F0F0F0"
//                }
//                else
//                {
//                    Inputs[k].parentElement.parentElement.style.backgroundColor="#FFFFFF"
//                }
//             }
//         }
         
        // 另一种方法，不过与下面的getCheckedItem()方法相冲突，不可同时使用它与getCheckedItem()
        // var newBox = chkbox;
        // vState = newBox.checked;
        // elem = newBox.form.elements;
        // for(var i=0;i<elem.length;i++)
        // {
        //     if(elem[i].checked != vState)
        //        elem[i].click();                    
        // }
        
               
        
      }	
          
          
          
       /* js方法得到GridView里选中项的个数
        *
        * 说明:判断GridView里的CheckBox至少有一项是选中的,并给出提示是选择了一项还是多项
        *
        * 使用方法:
        *       <input type="button" onclick="getCheckedItem('CheckBox1','GridView1');" />
        *
        * 参数说明: 第一个参数为GridView里CheckBox的ID,第二个参数为GridView的ID
        */
       function getCheckedItem(chkbox,gv)
       {   
           //get target base & child control.  
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;   
            
            //声明计数器变量
            var counter = 0;
            
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for(var n = 0; n < Inputs.length; ++n)      
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)          
                        if(Inputs[n].checked) 
                        counter ++;
                        
                }   
            if(counter > 0) 
            {
                if(counter == 1)
                    return confirm("Are you sure you want to delete this record?");
                else
                    return confirm("Are you sure you want to delete these records?");
            }
            else
            {
                alert('You must select an item');    
                return false; 
            }            
        }
        
        
          function CheckedItemOrNot(chkbox,gv,type)
       {   
           //get target base & child control.  
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;   
            
            //声明计数器变量
            var counter = 0;
            
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for(var n = 0; n < Inputs.length; ++n)      
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)          
                        if(Inputs[n].checked) 
                        counter ++;
                        
                }   
            if(counter > 0) 
            {
                if(counter == 1)
                    return confirm("Are you sure you want to "+type+" this record?");
                else
                    return confirm("Are you sure you want to "+type+" these records?");
            }
            else
            {
                alert('You must select an item');    
                return false; 
            }            
        }
             /* js方法得到GridView里选中项的个数
        *
        * 说明:判断GridView里的CheckBox至少有一项是选中的,并给出提示是选择了一项还是多项
        *
        * 使用方法:
        *       <input type="button" onclick="getCheckedItem('CheckBox1','GridView1');" />
        *
        * 参数说明: 第一个参数为GridView里CheckBox的ID,第二个参数为GridView的ID
        */
       function getCheckedItemforApprove(chkbox,gv)
       {   
           //get target base & child control.  
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;   
            
            //声明计数器变量
            var counter = 0;
            
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for(var n = 0; n < Inputs.length; ++n)      
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)          
                        if(Inputs[n].checked) 
                        counter ++;
                        
                }   
            if(counter > 0) 
            {
                if(counter == 1)
                    return confirm("Are you sure you want to approve this record?");
                else
                    return confirm("Are you sure you want to approve these records?");
            }
            else
            {
                alert('You must select an item');    
                return false; 
            }            
        }
        
        
          function getCheckedItemforStatement(chkbox,gv)
       {   
           //get target base & child control.  
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;   
            
            //声明计数器变量
            var counter = 0;
            
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for(var n = 0; n < Inputs.length; ++n)      
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)          
                        if(Inputs[n].checked) 
                        counter ++;
                        
                }   
            if(counter > 0) 
            {
                if(counter == 1)
                    return confirm("Are you sure you want to statement this record?");
                else
                    return confirm("Are you sure you want to statement these records?");
            }
            else
            {
                alert('You must select an item');    
                return false; 
            }            
        }
        
        /* js方法得到GridView里选中项的个数
        *
        * 说明:判断GridView里的CheckBox至少有一项是选中的,并给出提示是选择了一项还是多项
        *
        * 使用方法:
        *       <input type="button" onclick="getCheckedItem('CheckBox1','GridView1');" />
        *
        * 参数说明: 第一个参数为GridView里CheckBox的ID,第二个参数为GridView的ID
        */
       function getCheckedItemforPay(chkbox,gv)
       {   
           //get target base & child control.  
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;   
            
            //声明计数器变量
            var counter = 0;
            
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for(var n = 0; n < Inputs.length; ++n)      
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)          
                        if(Inputs[n].checked) 
                        counter ++;
                        
                }   
            if(counter > 0) 
            {
                if(counter == 1)
                    return confirm("Are you sure you want to pay this record?");
                else
                    return confirm("Are you sure you want to pay these records?");
            }
            else
            {
                alert('You must select an item');    
                return false; 
            }            
        }
        /*判断GridView是否只选中了一个CheckBox
         *       
         *说明: 判断GridView里的CheckBox是否只选中了一项
         *
         *使用方法如上
         */
         function getOneCheckedItem(chkbox,gv)
         {
            //get target base & child control.  
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;   
            
            //声明计数器变量
            var counter = 0;
            
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for(var n = 0; n < Inputs.length; ++n)      
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)          
                        if(Inputs[n].checked) 
                        counter ++;
                        
                }   
            if(counter > 0) 
            {
                if(counter == 1)
                {
                    return true;
                }
                else
                {
                    alert("Please select just one item");
                    //document.getElementById("lblMsg").value = "只能选择一项!";
                    return false;
                }
            }
            else
            {
                alert("Please select one item");
                //document.getElementById("lblMsg").value = "请选择一项!";
                return false; 
            }
         }
         
         
          /*判断GridView是否只选中了一个CheckBox
         *       
         *说明: 判断GridView里的CheckBox是否只选中了一项,如果选中一项则弹出窗口
         *
         *使用方法如上
         */
         
         var myPage;
         var newMyPage;
         function ShowActions(chkbox,gv,url)
         {         
            //get target base & child control.  
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;   
            
            //声明计数器变量
            var counter = 0;
            
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
            for(var n = 0; n < Inputs.length; ++n)      
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)          
                        if(Inputs[n].checked) 
                        counter ++;                        
                } 
            if(counter > 0) 
            {
                if( !myPage || myPage.closed || myPage == null || myPage == 'undefined' )
		        {
			        myPage = window.open(url, 'newwindow', 'height=300, width=200, top=200, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
		            myPage.focus();
		        }
		        else
		        {
		            //alert(newMyPage.name);
		            myPage.focus();
//		            myPage.close();	      
//			        myPage = window.open (url, 'newwindow', 'height=300, width=200, top=200, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
		        }
                
//                if(window.opener != null)
//                {
//                    window.opener.close();
//                }
//                window.open (url, 'newwindow', 'height=300, width=200, top=200, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
                return true;
              
            }
            else
            {
                alert('You must select an item');    
                return false; 
            }
         }
         
       /*   GridView 选中某一行 变换背景色 
        *   
        *
        * 
        */
        function changeRowBgColor(chkbox,gv)
        {
            var e = event.srcElement;
            
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;               
                        
            //get all the control of the type INPUT in the base control.           
            var Inputs = TargetBaseControl.getElementsByTagName("input");
                       
            for(var n = 0; n < Inputs.length; ++n)      
            {
                if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0) 
                {
                    if(Inputs[n].checked) 
                    {
                        Inputs[n].parentElement.parentElement.style.backgroundColor = "#C8C4DB";
                    }     
                    else
                    {
                        if( n % 2 == 0)
                        {
                            Inputs[n].parentElement.parentElement.style.backgroundColor = "#F0F0F0";                            
                        }
                        else
                        {
                            Inputs[n].parentElement.parentElement.style.backgroundColor = "#FFFFFF";                               
                        }         
                    }
                }                   
            }             
        }
       /*   GridView 改变背景颜色 隔行变色
        *   
        *
        * 
        */
        function changeGridViewBgColor(chkbox,gv)
        {       
            var TargetBaseControl = document.getElementById(gv);   
            var TargetChildControl = chkbox;  
            
            var Inputs = TargetBaseControl.getElementsByTagName("input"); 
            for(var n = 0; n < Inputs.length; ++n)
            {
                if(n % 2 == 0)
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0) 
                    {
                        if(!Inputs[n].checked) 
                        {
                            Inputs[n].parentElement.parentElement.style.backgroundColor="#F0F0F0";
                        }
                        else
                        {
                            Inputs[n].parentElement.parentElement.style.backgroundColor="#C8C4DB";
                        }
                    }    
                }
                else
                {
                    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0) 
                    {
                        if(!Inputs[n].checked) 
                        {
                            Inputs[n].parentElement.parentElement.style.backgroundColor="#FFFFFF";
                        }
                        else
                        {
                            Inputs[n].parentElement.parentElement.style.backgroundColor="#C8C4DB";
                        }
                    }
                }
            }       
        }
         